module guessing(
	// Clock Input (50 MHz)
	input  CLOCK_50,
	//  Push Buttons
	input rst,
	input scan_code,
	input scan_ready,
	output [7:0] history1,
	reg [7:0] history1;
	output [7:0] history2
	reg [7:0] history2;
);

	wire reset = 1'b0;

	// for hangman, the search registers contain what you entered in the previous state
	wire [7:0] search[15:0];
	assign search[3] = 8'h3B; // j
	assign search[2] = 8'h24; // e
	assign search[1] = 8'h2B; // f
	assign search[0] = 8'h2B; // f

	reg [17:0] oldReveal = 0;
	reg [17:0] reveal = 0; // the reveal array tells which elements to pass through and which to keep as blocks

	always @(posedge scan_ready or negedge rst) // fires when there's a key pressed or released
	begin
		if(~rst)
		begin
			history1 <= 0;
			history2 <= 0;
			oldReveal <= 0;
			reveal <= 0;
		end
		else
		begin
			history2 <= history1;
			history1 <= scan_code;
		 
			if(history1 == 8'hF0) // check for matches on release
			begin
				if(reveal == oldReveal) // incorrect guess because reveal array wasn't updated on key press
				begin
					reveal[17] <= 1'b1;
				end
				oldReveal <= reveal;
			end
			else // key press, update the reveal array
			begin
				if(scan_code == search[0])
					reveal[0] <= 1'b1;
				if(scan_code == search[1])
					reveal[1] <= 1'b1;
				if(scan_code == search[2])
					reveal[2] <= 1'b1;
				if(scan_code == search[3])
					reveal[3] <= 1'b1;
			end
		end
	end
		 
	//assign LEDR = reveal;

endmodule